<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>{$label}列表</h2>
        <ol class="breadcrumb">
            <li>
                <a href="{:url('admin/index/index')}">控制台</a>
            </li>
            <li class="active">
                <strong>查看列表</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2">
        {if condition="$buttons['create'] eq 1"}
        <h2><a href="{:url('admin/'.$route.'/create')}" class="btn btn-success" type="button"><i class="fa fa-plus"></i> 新增</a></h2>
        {/if}
    </div>
</div>
<div class="wrapper wrapper-content animated ">
<!--<div class="wrapper wrapper-content animated ">-->
<div class="row">
    {if $buttons['search'] == 1}
    <div class="col-lg-12">
        <div class="ibox float-e-margins">
            <div class="ibox-content text-center">
                <form role="form" action="{:url('/admin/'.$route)}" class="form-inline" method="get">
                    {foreach $searchFields as $k => $v}
                    <div class="form-group">
                        <?php if(!empty($translations[$v['field']]['type'])){ ?>
                        {switch name="$translations[$v['field']]['type']" }
                            {case value="status"}
                                <select class="form-control" name="{$v['field']}">
                                    <option value="">全部</option>
                                    {foreach $translations[$v['field']]['label'] as $_k => $_v}
                                    <option value="{$_k}" <?php if(request()->get($v['field']) == $_k){ ?> selected <?php } ?>>{$_v['text']}</option>
                                    {/foreach}
                                </select>
                            {/case}
                            {default /}
                                <input type="text" placeholder="{$translations[$v['field']]['text']}" name="{$v['field']}" value="<?php echo request()->get($v['field']); ?>"
                               class="form-control">
                        {/switch}
                        <?php }else{ ?>
                            <input type="text" placeholder="{$translations[$v['field']]['text']}" name="{$v['field']}" value="<?php echo request()->get($v['field']); ?>"
                               class="form-control">
                        <?php } ?>
                    </div>
                    {/foreach}
                    <button class="btn btn-info btn-outline" type="submit">搜索</button>
                </form>
            </div>
        </div>
    </div>
    {/if}
    <div class="col-lg-12">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <div class="row">
                    <div class="col-sm-5 m-b-xs">
                    </div>
                    <!--<div class="col-sm-3" style="float: right">-->
                        <!--<div class="input-group"><input type="text" placeholder="Search" class="input-sm form-control"> <span class="input-group-btn">-->
                                        <!--<button type="button" class="btn btn-sm btn-primary"> Go!</button> </span></div>-->
                    <!--</div>-->
                </div>
                <table class="table table-hover" id="list">
                    <thead>
                    <tr>
                        {if condition="$buttons['delete'] eq 1"}<th>选择</th>{/if}
                        {foreach $listFields as $vo}
                        <?php if(!empty($translations[$vo]['width'])){  ?>
                            <th width="$translations[$vo]['width']">{$translations[$vo]['text']}</th>
                        <?php }else{ ?>
                            <th>{$translations[$vo]['text']}</th>
                        <?php } ?>
                        {/foreach}
                        <th width=""></th>
                        <div style="clear:both;"></div>
                    </tr>
                    </thead>
                    <tbody>
                    {empty name="list"}<tr><td style="text-align: center" colspan="{:count($translations)+1}">暂无数据</td></tr>{/empty}
                    {foreach $list as $v}
                    <tr>
                        {if condition="$buttons['delete'] eq 1"}<td><input type="checkbox" value="{$v['id']}" class="ids"></td>{/if}
                        {foreach $listFields as $x}
                        <?php if(empty($translations[$x]['type'])){ ?>
                        <td>{$v[$x]}</td>
                        <?php }else{ ?>
                        {switch name="$translations[$x]['type']" }
                            {case value="status"}
                                <td>
                                    <?php if(!empty($v[$x])){  ?>
                                    <span class="{$translations[$x]['label'][$v[$x]]['class']}">{$translations[$x]['label'][$v[$x]]['text']}</span>
                                    <?php } ?>
                                </td>
                            {/case}
                            {case value="image"}
                            <td>
                                <a href="{$v[$x]}" target="_blank"><img src="{$v[$x]}" width="40px" style="border-radius: 50%"></a>
                            </td>
                            {/case}
                            {default /} <td>{$v[$x]}</td>
                        {/switch}
                        <?php } ?>
                        {/foreach}
                        <td>
                            {if condition="$buttons['edit'] eq 1"}
                                <a href="{:url('/admin/'.$route.'/'.$v['id'].'/edit')}" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i> 编辑</a>
                            {/if}
                            {if condition="$buttons['delete'] eq 1"}
                                <a onclick="del({$v['id']})" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> 删除</a>
                            {/if}
                            <?php if(!empty($moreButtons)){ foreach($moreButtons as $_k => $_v){ ?>
                            <a href="{$_v['a']}" class="{$_v['class']}" id="{$_v['id']}">{$_v['text']}</a>
                            <?php }} ?>
                        </td>
                        <div style="clear: both"></div>
                    </tr>
                    {/foreach}
                    </tbody>
                </table>
                {if condition="$buttons['delete'] eq 1"}
                <label><input type="checkbox" class="all"> 全选</label> &nbsp;&nbsp;&nbsp;<button class="btn btn-danger btn-sm" id="del-all">删除</button>
                {/if}

               {if condition = "$buttons['daochu'] eq 1" }
                <button class="btn btn-danger btn-sm" id="dao-all">导出</button>
                {/if}
                <?php if(!empty($list->render())){ ?>
                <div style="text-align: center"> {$list->render()}</div>
                <?php } ?>
            </div>
        </div>
    </div>
<script>
    function del(id) {
        layer.confirm('你确认删除此条记录吗？', {
            btn: ['确认','取消']
        }, function(){
            var index = layer.load(1);
            $.ajax({
                type:"DELETE",
                url:"{:url('/admin/'.$route.'/"+id+"')}",
                //返回数据的格式
                datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
                //成功返回之后调用的函数
                success:function(data){
                    layer.close(index);
                    if (data.status == 1){
                        layer.msg('删除成功', {icon:1, time:600}, function () {
                            window.location.reload();
                        })
                    }else {
                        layer.msg(data.msg, {icon:2, time:800})
                    }
                },
                //调用出错执行的函数
                error: function(){
                    layer.close(index);
                    layer.alert('系统异常')
                    //请求出错处理
                }
            });
        });
    }
    function getValues(){
        var ids = '';

        $("#list :checkbox").each(function(i){
            if ($(this).is(":checked")){
                ids += $(this).val()+',';
            }
        });
        return ids;
    }
</script>
    <script>
        $(function () {
            //全选或全不选
            $(".all").click(function(){
                if(this.checked){
                    $("#list :checkbox").prop("checked", true);
                }else{

                    $("#list :checkbox").prop("checked", false);
                }
            });

            $('#del-all').click(function () {
                var id = getValues();
                if (id == ''){
                    layer.msg('请选择需要删除的记录！');
                    return false;
                }
                layer.confirm('你确认删除选择的记录吗？', {
                    btn: ['确认','取消']
                }, function() {
                    var index = layer.load(1);


                    $.ajax({
                        type: "DELETE",
                        url: "{:url('/admin/'.$route.'/" + id + "')}",
                        //返回数据的格式
                        datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
                        //成功返回之后调用的函数
                        success: function (data) {
                            layer.close(index);
                            if (data.status == 1) {
                                layer.msg('删除成功', {icon: 1, time: 600}, function () {
                                    window.location.reload();
                                })
                            } else {
                                layer.msg(data.msg, {icon: 2, time: 800})
                            }
                        },
                        //调用出错执行的函数
                        error: function () {
                            layer.close(index);
                            layer.alert('系统异常')
                            //请求出错处理
                        }
                    });
                })
            })

            $('#dao-all').click(function () {


                    alert("{:url('/admin/'.$route.'/daochu')}")
                $.ajax({

                    url:"{:url('/admin/'.$route.'/daochu')}",

                    type:'get',
                    success:function (data) {
                        alert(data)
                    }

                })

            })
        });
    </script>
</div>
</div>